package com.ah.shanxi_demo.common;

import com.ah.shanxi_demo.param.result.NowMonthDaysTimes;
import com.alibaba.fastjson.JSON;

import java.util.*;

/**
 * @author zt 2020/8/25
 */
public class SXDateUtils {

    public static final String CONSTANT_START=" 00:00:01";
    public static final String CONSTANT_END=" 23:59:59";


    /**
     * 获取当月最大天数
     * @return
     */
    public static Integer query_now_month_days(){
        Calendar instance = Calendar.getInstance();
        instance.set(Calendar.DATE,1);
        instance.roll(Calendar.DATE,-1);
        int maxDays = instance.get(Calendar.DATE);
        return maxDays;
    }

    /**
     * 获取当月 每一天的日期
     * @return
     */
    public static List<NowMonthDaysTimes> query_now_month_date(Long registerId){

        List<NowMonthDaysTimes> list=new ArrayList<>();

        List<Date> dateList = query_now_month_date();

        dateList.stream().forEach(date -> {

            NowMonthDaysTimes model=new NowMonthDaysTimes();
            String shortDate = TimeUtils.parseShortDate(date);

            model.setStartTime(shortDate+CONSTANT_START);
            model.setEndTime(shortDate+CONSTANT_END);
            model.setRegisterId(registerId);

            list.add(model);

        });
        return list;
    }

    /**
     * 获取当月 每一天的日期
     * @return
     */
    public static List<Date> query_now_month_date(){
        Calendar calendar = Calendar.getInstance();
        int now_year = calendar.get(Calendar.YEAR);
        int now_month = calendar.get(Calendar.MONTH);

        calendar.set(now_year,now_month,1);

        List<Date> list=new ArrayList<>();
        do {
            list.add(calendar.getTime());
            calendar.add(Calendar.DAY_OF_MONTH,1);
        }while (now_month == calendar.get(Calendar.MONTH));

        return list;
    }





    public static void main(String[] args) {

        List<NowMonthDaysTimes> list = query_now_month_date(Long.valueOf(1));
        System.out.println(JSON.toJSONString(list));
    }

}
